#include "Player.h"

void Player::dummySetBaseStats() {
	switch(_playerClass->getClass()) {
	case PlayerClass::MAGE:	_playerStats->setStats(15, 23, 7); break;
	case PlayerClass::WARRIOR:	_playerStats->setStats(24, 16, 5); break;
	case PlayerClass::GOD:	_playerStats->setStats(666, 666, 666); break;
	default: 	_playerStats->setStats(1, 1, 1);
	}
}

Player::Player(void) {	
	setName("Dummy");
	_playerClass = new PlayerClass("DUMMY");
	_playerStats = new PlayerStats();
	this->dummySetBaseStats();
	_playerAlive = true;
	_playerInCombat = false;
	_playerTarget = NULL;
}

Player::Player(string name, string classType) : 
	_playerName(name) {
	_playerClass = new PlayerClass(classType);
	_playerStats = new PlayerStats();
	this->dummySetBaseStats();
	_playerTarget = NULL;
	_playerAlive = true;
	_playerInCombat = false;
}

Player::~Player(void) {
}

void Player::setTarget(Entity* target) {
	_playerTarget = target;
}

Entity* Player::getTarget() {
	return _playerTarget;
}

void Player::setName(string name) {
	_playerName = name;
}

string Player::getName() {
	return _playerName;
}

void Player::setAlive(bool isAlive) {
	_playerAlive = isAlive;
}

bool Player::isAlive() {
	return _playerAlive;
}

void Player::setCombat(bool isInCombat) {
	_playerInCombat = isInCombat;
}

bool Player::isInCombat() {
	return _playerInCombat;
}

bool Player::attack() {
 	if(_playerTarget == NULL || !_playerTarget->isAlive())
		return false;
	else {
		_playerTarget->getAttacked(_playerStats->getDamage() + _playerStats->getBonusDamage());
		return true;
	}
}

PlayerClass*& Player::getPlayerClass(){
	return _playerClass;
}

void Player::setPlayerClass(const PlayerClass*& playerClass) {
	_playerClass = new PlayerClass(playerClass);
}

const PlayerStats*& Player::getPlayerStats() {
	return (const PlayerStats*&)_playerStats;
}

void Player::setPlayerStats(const PlayerStats*& playerStats) {
	_playerStats = new PlayerStats(playerStats);
}

PlayerClass* Player::getClass() {
	return _playerClass;
}

PlayerStats* Player::getStats() {
	return _playerStats;
}

void Player::getAttacked(int damage) {
	if(damage >= _playerStats->getHitPoints()) {
		_playerStats->setHitPoints(0);
		setAlive(false);
	} else {
		_playerStats->setHitPoints(_playerStats->getHitPoints() - damage);
	}
}

